/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package demo.model.dao;

import demo.model.dto.IDataSourceTO;
import demo.model.dto.ProductTO;
import demo.model.util.SqlBundle;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;



/**
 *
 * @author Admin
 */
public class ProductDA extends ObjectDA{

    public ProductDA(IDataSourceTO settingTO, SqlBundle sqlBundle) {
        super(settingTO,sqlBundle);
    }
    
    public ArrayList<ProductTO> getAllProduct()throws Exception{
        ArrayList<ProductTO> listProduct=new ArrayList<ProductTO>();
        Connection conn=super.createConnection();
        PreparedStatement pre=super.createPrepareStatement("getAllProduct", conn);
        ResultSet rs=pre.executeQuery();
        ProductTO product;
        while(rs.next()){
            product=new ProductTO();
            product.setID(rs.getInt("ID"));
            product.setName(rs.getString("name"));
            product.setPrice(rs.getDouble("price"));
            product.setNote(rs.getString("note"));
            listProduct.add(product);
        }
        return listProduct;
    }
    public void insertProduct(ProductTO product)throws Exception{
        Connection conn=super.createConnection();
        PreparedStatement pre=super.createPrepareStatement("insertProduct", conn);
        pre.setNString(1,product.getName());
        pre.setDouble(2, product.getPrice());
        pre.setNString(3,product.getNote());
        pre.execute();
        super.close(conn, pre);
    }
    
    @Override
    protected String getSqlBundleName() {
        return "sql_Product";
    }

}
